package com.higold.cloud.mvp.presenter

import com.higold.cloud.base.BasePresenter
import com.higold.cloud.mvp.contract.UserInfoContract
import com.higold.cloud.mvp.model.UserInfoModel
import com.higold.cloud.net.exception.ExceptionHandle

/**
 *    author : lxz
 *    date   : 2019/9/10 9:15
 *    desc   :
 */
class UserInfoPresenter : BasePresenter<UserInfoContract.View>(), UserInfoContract.Presenter {

    private val userInfoModel by lazy { UserInfoModel() }

    override fun requestUserInfo(accountId: Int) {
        checkViewAttached()
        mRootView?.showLoading()
        val disposable = userInfoModel.getUserInfo(accountId)
                .subscribe({ userInfo ->
                    mRootView?.setUserInfo(userInfo)
                }, { throwable ->
                    //处理异常
                    mRootView?.showError(ExceptionHandle.handleException(throwable), ExceptionHandle.errorCode)
                })
        addSubscription(disposable)
    }
}